mod element;
mod lexer;
pub mod parser;

#[cfg(test)]
mod test {
    use logos::Logos;

    use crate::parse::lexer::ExprToken;

    use super::{lexer, parser::parse};

    #[test]
    fn lexer_test() {
        let input = "1 + 2 / (3 + 1* <CuSO4 5H2O>)";
        let mut expr_lex = lexer::ExprToken::lexer(input);
        let _ = expr_lex.next();
        loop {
            if let Some(Ok(term_token)) = expr_lex.next() {
                println!("{:?}", term_token);

                if let ExprToken::Chemical(chemical) = term_token {
                    let mut chem_lex = lexer::ChemToken::lexer(&chemical[1..chemical.len() - 1]);
                    loop {
                        if let Some(Ok(chem_token)) = chem_lex.next() {
                            println!("\t{:?}", chem_token);
                        } else {
                            break;
                        }
                    }
                }
            } else {
                break;
            }
        }
    }

    #[test]
    fn expr_parser_test() {
        // println!("res: {}", parse("1"));
        // println!("res: {}", parse("1+2*3"));
        // println!("res: {}", parse("1 + 2 * 3 * 4 + 5"));
        // println!("res: {}", parse("(((1+2))*3*(4+5))"));
        println!(
            "res: {}",
            parse("(2 * <Cu SO4 ( 5(  ( H2 )O  ))> / 2 + 0.4) + 3").unwrap()
        );
        println!("res: {}", parse("<Cu S O4 5H2O>").unwrap());
    }
}
